package com.douguo.recipe.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

import com.douguo.recipe.EKMainActivity;
import com.douguo.recipe.HomeActivity;
import com.douguo.recipe.R;
import com.douguo.recipe.SettingActivity;
import com.douguo.recipe.SortActivity;

public class NavigationView {
	public static final int STATE_NONE = -1;
	public static final int STATE_HOME = 0;
	public static final int STATE_SORT = 1;
	public static final int STATE_SEARCH = 2;
	public static final int STATE_MAGAZINE = 3;
	public static final int STATE_MORE = 4;
	private static int mState = STATE_HOME;
	private Context mContext;
	private ImageButton mBtnSort;
	private ImageButton mBtnSearch;
	private ImageButton mBtnHome;
	private ImageButton mBtnMagazine;
	private ImageButton mBtnMore;

	public NavigationView(Context context, int state) {
		
		mContext = context;
		final Activity activity = (Activity) mContext;
		mBtnSort = (ImageButton) activity.findViewById(R.id.bottom_classify);
		mBtnSearch = (ImageButton) activity.findViewById(R.id.bottom_search);
		mBtnSort.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(activity, SortActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				activity.startActivity(intent);

			}
		});

		mBtnSearch.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				activity.onSearchRequested();
			}
		});
		mBtnHome = (ImageButton) activity.findViewById(R.id.bottom_home);
		mBtnHome.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(activity, HomeActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
				activity.startActivity(intent);

			}
		});
		mBtnMagazine = (ImageButton) activity.findViewById(R.id.bottom_magazine);
		mBtnMagazine.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(activity, EKMainActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				activity.startActivity(intent);
			}
		});
		mBtnMore = (ImageButton) activity.findViewById(R.id.bottom_more);
		mBtnMore.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(activity, SettingActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				activity.startActivity(intent);
			}
		});
		initPic(state);
	}

	public void initPic(int state) {
//		Activity activity = (Activity) mContext;
//		mBtnAbout.setImageResource(R.drawable.btn_about);
//		mBtnSearch.setImageResource(R.drawable.btn_gosearch);
//		mBtnSort.setImageResource(R.drawable.btn_sort);
//		mBtnCalendar.setImageResource(R.drawable.btn_calendar);
//		mBtnFavor.setImageResource(R.drawable.btn_favor);
		switch (state) {
		case STATE_HOME:
			mBtnHome.setImageResource(R.drawable.btn_home);
			break;
		case STATE_NONE:
			break;
		case STATE_SEARCH:
			mBtnSearch.setImageResource(R.drawable.btn_search);
			break;
		case STATE_SORT:
			mBtnSort.setImageResource(R.drawable.btn_sort);
			break;
		case STATE_MAGAZINE:
			mBtnMagazine.setImageResource(R.drawable.btn_magazine);
			break;
		case STATE_MORE:
			mBtnMore.setImageResource(R.drawable.btn_more);
			break;
		}
		mState = state;
		switch (state) {
		case STATE_HOME:
			mBtnHome.setImageResource(R.drawable.btn_home_press_img);
			break;
		case STATE_NONE:
			break;
		case STATE_SEARCH:
			mBtnSearch.setImageResource(R.drawable.btn_search_press_img);
			break;
		case STATE_SORT:
			mBtnSort.setImageResource(R.drawable.btn_sort_press_img);
			break;
		case STATE_MAGAZINE:
			mBtnMagazine.setImageResource(R.drawable.btn_magazine_press_img);
			break;
		case STATE_MORE:
			mBtnMore.setImageResource(R.drawable.btn_more_press_img);
			break;
		}
	}
}
